package com.example.demo.publisher;

import com.example.demo.annotation.ApiLog;
import com.example.demo.entity.LogApi;
import com.example.demo.event.ApiLogEvent;
import com.example.demo.util.SpringUtil;
import com.example.demo.util.WebUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * API日志信息事件发送
 *
 * @author cici
 */
public class ApiLogPublisher {

	public void publishEvent(String methodName, String methodClass, ApiLog apiLog, long time) {
		HttpServletRequest request = WebUtil.getRequest();
		LogApi logApi = new LogApi();
		logApi.setType("1");
		logApi.setTitle(apiLog.value());
		logApi.setTime(String.valueOf(time));
		logApi.setMethodClass(methodClass);
		logApi.setMethodName(methodName);
		Map<String, Object> event = new HashMap<>(16);
		event.put("log", logApi);
		SpringUtil.publishEvent(new ApiLogEvent(event));
	}

}
